package com.wufeng.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wufeng.dto.ArticleUserDto;
import com.wufeng.entity.Article;
import com.wufeng.mapper.ReplyMapper;
import com.wufeng.service.ArticleService;
import com.wufeng.mapper.ArticleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Hxh
 * @description 针对表【article】的数据库操作Service实现
 * @createDate 2023-12-19 21:39:01
 */
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article>
        implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;



    /**
     * 根据id增加文章的回复数
     * @return
     */
    @Override
    public Boolean addReplycountById(int articleId) {
        int result = articleMapper.addReplycountById(articleId);
        return result > 0 ? true : false;
    }

    @Override
    public Boolean minusReplycountById(int articleId) {

        int result = articleMapper.minusReplycountById(articleId);
        return result > 0 ? true : false;
    }

    @Override
    public void decrementLikeCount(Integer articleid) {
        articleMapper.decrementLikeCount(articleid);
    }

    @Override
    public void incrementLikeCount(Integer articleid) {
        articleMapper.incrementLikeCount(articleid);
    }

    @Override
    public List<ArticleUserDto> getArticleListByCondition(Article article, Integer pageIndex, Integer pageSize) {
        Integer startIndex = (pageIndex-1) * pageSize;
        return articleMapper.getArticleListByCondition(article,startIndex, pageSize);
    }
}




